﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace PSE.Deployment.SetupBase.Configuration.Actions
{
    [Serializable]
    public class InstallWindowsService : ActionBase
    {
        public List<WindowsService> Services { get; set; }

        public InstallWindowsService()
        {
            Services = new List<WindowsService>();
        }

        public override bool HasFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath) || this.Services == null || this.Services.Count == 0)
                return false;
            else
            {
                return this.Services.Exists(s => (s.ConfigFile != null && filePath.Equals(Path.Combine(PSE.Deployment.Util.File.RemoveRootLevel(s.ConfigFile.Destination), s.ConfigFile.FileName), StringComparison.CurrentCultureIgnoreCase)) ||
                                                (s.ServiceFile != null && filePath.Equals(Path.Combine(PSE.Deployment.Util.File.RemoveRootLevel(s.ServiceFile.Destination), s.ServiceFile.FileName), StringComparison.CurrentCultureIgnoreCase))
                                            );
            }
        }
    }
}
